﻿Chenxin.UI.EmpSettingMgr=Chenxin.extend(Chenxin.UI.PageCommon,{
	actionUrl:'service/EmpSettingMgr.ashx',
	idList:[],
	createGrid:function(){		
					
		return new Chenxin.UI.ExpandGrid({
			actionUrl:this.actionUrl+'?op=getlist',
			id:'esmtable',
			renderTo:'esm_table',
			height:290,
			columns:{
				UserCode:{
					head:'工号',
					width:90
				},
				UserName:{
					head:'姓名',
					width:120			
				},
				Company:{
					head:'公司',
					width:120			
				},
				DepartName:{
					head:'部门',
					width:150			
				},
				IsBelong:{
					width:40,head:'隶属'
				},
				IsControl:{
					width:40,head:'管辖'
				},
				IsRoleA:{
					width:45,head:'业务员'
				},
				IsRoleB:{
					width:40,head:'秘书'
				},
				IsRoleC:{
					width:40,head:'店长'
				},
				IsRoleD:{
					width:40,head:'高经'
				},
				IsRoleE:{
					width:40,head:'区经'
				},
				IsRoleF:{
					width:40,head:'商经'
				},
				ViewPubHouse:{
					width:40,head:'公盘'
				},
				ViewPrivHouse:{
					width:40,head:'私盘'
				},
				ViewHideHouse:{
					width:75,head:'查隐藏盘源'
				},
				DelHouse:{
					width:60,head:'删除房源'
				},
				SetPubLevel:{
					width:100,head:'客源公开级别'
				},
				ViewPrivCustomer:{
					width:60,head:'私客信息'
				},
				ViewPubShareCustomer:{
					width:150,head:'查看部门共享客户'
				},
				ViewCrossPubShareCustomer:{
					width:150,head:'查看跨部门共享客户'
				},
				ShiftPubCustomer:{
					width:100,head:'转移公开客源'
				},
				EditPubCustomer:{
					width:60,head:'修改公客'
				},
				EditPrivCustomer:{
					width:60,head:'修改私客'
				},
				ViewPrivDemand:{
					width:60,head:'私客需求'
				},
				ViewPubShareDemand:{
					width:150,head:'查看部门共享客需'
				},
				ViewCrossPubShareDemand:{
					width:150,head:'查看跨部门共享客需'
				},
				EditPubDemand:{
					width:60,head:'修改公需'
				},
				EditPrivDemand:{
					width:60,head:'修改私需'
				},
				ViewRealCustomer:{width:50,head:'真业主'},
				ViewFakeCustomer:{width:50,head:'假业主'},
				EditPrimaryHouse:{width:120,head:'修改房源关键字段'},
				EditNormalHouse: { width: 130, head: '修改房源非关键字段' },
				viewtrace: { width: 60, head: '查看跟单' },
				DelTrace:{width:60,head:'删除跟单'},
				CanProtect:{width:120,head:'保护/取消保护'},
				CanLockHouse:{width:60,head:'封盘操作'},
				CancelLockHouse:{width:60,head:'取消封盘'},

				ViewLockHouse:{width:60,head:'查看封盘'},

				ViewWatching:{width:60,head:'查看带看'},
				EditWatching:{width:60,head:'修改带看'},
				EditKey:{width:60,head:'修改钥匙'},
				UseKey:{width:60,head:'钥匙使用'},
				EditKeyUsing:{width:100,head:'修改钥匙使用'},


				ViewChange:{width:60,head:'查看变更'},
				CanChangeConfirm:{width:60,head:'处理变更'},
				ViewEntrust:{width:60,head:'查看委托'},
				EditTrust:{width:60,head:'修改委托'},

				CanCancelTrust:{width:60,head:'作废委托'},
				UnCancelTrust:{width:60,head:'取消作废'},
				CanDelTrust:{width:60,head:'删除委托'},

				ViewHrInfo:{width:100,head:'可查人事信息'},
				ViewHrChange:{width:100,head:'可查人事变动'},
				ViewAttendance:{width:60,head:'可查考勤'},
				ViewVacation:{width:60,head:'可查休假'},
				ViewAnnualLeave:{width:60,head:'可查年假'},
				ViewStock:{width:60,head:'可查库存'},
				ViewTelLog:{width:100,head:'可查电话日志'},
				ViewBusiness:{width:100,head:'可查营业动态'},
				ViewUserLog:{width:100,head:'可查用户操作日志'},

				CanUploadPicture: { width: 100, head: '可上传房源图片' },
				CanDeletePicture: { width: 100, head: '可删除房源图片' },
				CanPublishHouse: { width: 100, head: '可推送房源' }
			},
			scope:this
		});
		// return new Chenxin.UI.Pagination({
			// actionUrl:this.actionUrl+'?op=getlist',
			// id:'esmtable',
			// renderTo:'esm_table',
			// data:{}
		// });
	},
	initEvent:function(){
		var _this=this;
		$('#btn_add').click(function(){
			_this.add('empsetting');
			//_this.form.reset();
		});
		$('#btn_edit').click(function(){
			_this.editSetting();
		});
		$('#btn_del').click(function(){
			
            _this.delList();
			// var _idList=[];
			// for(var i=0;i<_this.idList.length;i++){				
				// if(!$('#'+_this.idList[i]+' td:eq(5)').text()){
					// _idList.push(_this.idList[i]);
				// }
			// }
			// _this.del('','确定删除这几条设定记录吗？\n隶属设定将不会删除！','',{idlist:_idList.join(',')},_idList.length);
		});
		$('#btn_deldepart').click(function(){
			_this.delDepart();
		});
		
		$('#chk_all').live('click',function(){
			_this.idList=[];
			if(this.checked){				
				$(':checkbox[name="chk_record"]').each(function(){
					_this.idList.push(this.id.substr(4));
					$('#'+this.id.substr(4)).addClass('selected_orgbgcolor');
				});	
			}else{
				$(':checkbox[name="chk_record"]').each(function(){
					$('#'+this.id.substr(4)).removeClass('selected_orgbgcolor');
				});				
			}
			$(':checkbox[name="chk_record"]').attr('checked',this.checked);			
		});
		
		$('#'+this.grid.renderTo+' :checkbox[name="chk_record"]').live('click',function(event){
			if(this.checked){
				_this.idList.push(this.id.substr(4));
				$('#'+this.id.substr(4)).addClass('selected_orgbgcolor');
			}else{				
				_this.idList.remove(this.id.substr(4));	
				$('#'+this.id.substr(4)).removeClass('selected_orgbgcolor');
			}
			
			if(_this.idList.length==1){
				_this.currentId=_this.idList[0];
			}else{
				_this.currentId=undefined;
			}
		});
		
		
		$('#'+this.grid.renderTo+' .tr_empsettinglist').live('click',function(e){
			if(e.target.tagName=='INPUT'){
				return;
			}
			var _chk=$('#chk_'+this.id);
			
			$('#'+_this.grid.renderTo+' .selected_orgbgcolor').removeClass('selected_orgbgcolor');
			$('#'+_this.grid.renderTo+' :checked[name="chk_record"]').attr('checked',false);
			_this.idList=[];
			_this.idList.push(this.id);
			_this.currentId=this.id;
			$(this).addClass('selected_orgbgcolor');
			_chk.attr('checked',true);
			
		});
		
		$('.tr_empsettinglist').live('mouseover',function(){
			$(this).toggleClass('orgbgcolor');
		});
		$('.tr_empsettinglist').live('mouseout',function(){
			$(this).toggleClass('orgbgcolor');
		});
		
		
	},
	createForm:function(){
		return new Chenxin.UI.EmpSettingForm({
				scope:this,
				op:'empsetting',
				autoHide:false,
				saveSucc:function(){
					this.reloadGrid();
				},
				afterGetFormJson:function(model){
					if(model.settingtype=='10'){//门店
						if(model.role){
							delete model.role;
						}
						if(model.usercode){
							delete model.usercode;
						}
						Chenxin.apply(this.form.additionalParam,model);
					}else if(model.settingtype=='20'){//个人
						if(model.depid){
							delete model.depid;
						}
						// var _usercode=this.form.findByName('usercode');
						// if(_usercode.currentNode){			
							// model.usercode=this.form.findByName('usercode').currentNode.code;
						// }
						Chenxin.apply(this.form.additionalParam,model);
					}else{
						//var _usercode=this.form.findByName('usercode');
						// if(_usercode.currentNode){		
							// this.form.additionalParam.usercode=_usercode.currentNode.code;
							// this.form.additionalParam.userid=model.usercode;
						// }
						// var _aimusercode=this.form.findByName('aimusercode');
						// if(_aimusercode.currentNode){			
							// this.form.additionalParam.aimusercode=_aimusercode.currentNode.code;
							// this.form.additionalParam.aimuserid=model.aimusercode;	
						// }	
						Chenxin.apply(this.form.additionalParam,model);	
						this.form.additionalParam.settingtype=30;
					}
					Chenxin.Fn.initObject(model);
				}
			});
	},
	createSearch:function(){
		return new Chenxin.UI.EmpSettingSearch({
			scope:this
		});
	},
	editSetting:function(){
		if(!this.currentId){
			alert('请选择一条记录进行编辑');
			return;
		}
		if(!this.editForm){
			this.editForm=new Chenxin.UI.EmpSettingEditForm({
				scope:this,
				op:'edit',
				saveSucc:function(){
					this.reloadGrid();
				}
			});
		}
		if(this.editForm.show()){
			Chenxin.Fn.getModel(this.currentId,this.actionUrl,function(model){
				this.fitData(model);
				this.scope.currentModel=model;
			},this.editForm);
		}
	},
	reloadGrid:function(searchModel,pageIndex){
		Chenxin.UI.EmpSettingMgr.superclass.reloadGrid.call(this,searchModel,pageIndex);
		this.idList=[];
		this.currentId=undefined;
	},
	delDepart:function(){
		if(!this.delDepartForm){
			this.delDepartForm=new Chenxin.UI.DelDepartForm({
				scope:this,
				op:'delbydep',
				saveSucc:function(){
					this.reloadGrid();
				}
			});
		}
		this.delDepartForm.show();
	},
	initComponent:function(){
		Chenxin.UI.EmpSettingMgr.superclass.initComponent.call(this);
	}
});

Chenxin.UI.EmpSettingSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
	id:'esm_search',
	initEvent:function(){		
		var _this=this;
		$('#btn_search').live('click',function(){
			_this.scope.reloadGrid();
		});
	},
	createComboList:function(){
		
        var depart=new Chenxin.UI.DepartTreeCombo({
            textBoxId:'esm_depart',
			name:'departid'
        });
        /*
        
        var user=new Chenxin.UI.UserTreeCombo({
            textBoxId:'esm_user',
			name:'userid'
        });*/
        return [depart]
	},
	initComponent:function(){		
		Chenxin.UI.EmpSettingSearch.superclass.initComponent.call(this);
	}
});

/**
*@description 人员设定编辑
*/
Chenxin.UI.DelDepartForm=Chenxin.extend(Chenxin.UI.FormCommon,{
	actionUrl:'service/EmpSettingMgr.ashx',
	id:'delDepartWin',
	renderTo:'jqm_delDepartWin',
	jqmWidth:400,
	title:'删除部门设定',
	afterGetFormJson:function(model){
		this.delDepartForm.additionalParam.departid=model.departid
	},
	initEvent:function(){	
		var _this=this;
		var filter='#'+this.id;
		$(filter+'_Save').live('click',function(){			
			_this.save();
		});
		$(filter+'_Cancle').live('click',function(){
			_this.hide();			
		});	
	},
	createComboList:function(){
		var depart=new Chenxin.UI.DepartTreeCombo({
            textBoxId:this.id+'_dep',
			name:'departid',
            singleSelect:true
        });
		return [depart];
	},
	createForm:function(){
		return Chenxin.FormCommon.delDepartForm(this.id);
	},
	initComponent:function(){
		Chenxin.UI.DelDepartForm.superclass.initComponent.call(this);
	}
	
});

/**
*@description 表单内容
*/
Chenxin.FormCommon.delDepartForm=function(comboIdPrefix){
return '<table class="tbl_f"><tr><th style="width:120px;">请选择部门：</th><td><input id="' + comboIdPrefix + '_dep" class="inputbox_n fl" type="text"  style="width:110px;margin-left: 5px;" /></td></tr><tr><td></td><td class="isfilled">将删除该部门所有非隶属的业务设定。</td></tr><tr><td colspan="2"><div class="tdline"></div></td></tr><tr><td colspan="2" align="right"><div style="float:right; margin-right:15px;"><a id="' + comboIdPrefix + '_Save" class="btn_n fl" href="#"><span>确定</span></a><a id="' + comboIdPrefix + '_Cancle"  class="btn_n fl" href="#"><span>取消</span></a></div></td></tr></table>';
}


/**
*@description 人员设定编辑
*/
Chenxin.UI.EmpSettingEditForm=Chenxin.extend(Chenxin.UI.FormCommon,{
	actionUrl:'service/EmpSettingMgr.ashx',
	id:'settingEditWin',
	renderTo:'jqm_settingEditWin',
	jqmWidth:700,
	title:'人员设定编辑',
	afterGetFormJson:function(model){
		var _p=',';
		for(var i=0;i<comboCommon.purview.length;i++){
			_p+=comboCommon.purview[i].val+',';
		}
		var _data={};
		for(var p in this.currentModel){
			if(_p.indexOf(','+p+',')==-1){
				_data[p]=this.currentModel[p];
			}
		}
		Chenxin.applyIf(model,_data);
	},
	initEvent:function(){	
		var _this=this;
		var filter='#'+this.id;
		$(filter+'_Save').live('click',function(){			
			_this.save();
		});
		$(filter+'_Cancle').live('click',function(){
			_this.hide();			
		});	
		this.initPreview();
	},
	initPreview:function(){
		var html='';
		var items=comboCommon.purview;
		for(var i=0;i<items.length;i++){
			var t=Math.random()*100000+'';
			var id='cx_'+t.split('.')[0]+'_'+t.split('.')[1];
			html+='<div style="float:left; width:130px;"><input type="checkbox" name="'+items[i].val+'" value="true" id="'+id+'"/><label for="'+id+'">'+items[i].txt+'</label></div>';
		}
		$('#td_'+this.id+'_purview').html(html);
	},
	createForm:function(){
		return Chenxin.FormCommon.empSettingEditForm(this.id);
	},
	initComponent:function(){
		Chenxin.UI.EmpSettingEditForm.superclass.initComponent.call(this);
	}
	
});

/**
*@description 表单内容
*/
Chenxin.FormCommon.empSettingEditForm=function(comboIdPrefix){
return '<table class="tbl_f"><tr><th style="width:100px;">工号：</th><td><input name="UserCode" class="inputbox_n fl" type="text"  style="width:160px;margin-left: 5px;" /></td><th>姓名：</th><td><input name="UserName" class="inputbox_n fl" type="text"  style="width:160px;margin-left: 5px;" /></td></tr><tr><th style="width:100px;">公司：</th><td><input name="Company" class="inputbox_n fl" type="text"  style="width:160px;margin-left: 5px;" /></td><th>部门：</th><td><input name="DepartName" class="inputbox_n fl" type="text"  style="width:160px;margin-left: 5px;" /></td></tr><tr><th>权限设定：</th><td colspan="3" id="td_' + comboIdPrefix + '_purview"></td></tr><tr><td colspan="4"><div class="tdline"></div></td></tr><tr><td colspan="4" align="right"><div style="float:right; margin-right:15px;"><a id="' + comboIdPrefix + '_Save" class="btn_n fl" href="#"><span>确定</span></a><a id="' + comboIdPrefix + '_Cancle"  class="btn_n fl" href="#"><span>取消</span></a></div></td></tr></table>';
}


$(document).ready(function(){
	var esm=new Chenxin.UI.EmpSettingMgr();
});

